package com.shopnight.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shopnight.entity.Organization;
import com.shopnight.entity.TakeoutMerchantCart;
import com.shopnight.service.OrganizationService;
import com.shopnight.mapper.OrganizationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 13201
 * @description 针对表【organization(组织表  如 湖北恩施学院)】的数据库操作Service实现
 * @createDate 2023-03-24 17:10:32
 */
@Service
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization>
        implements OrganizationService{

    @Autowired
    OrganizationMapper organizationMapper;

    @Override
    public List<Organization> getOrganizationOne() {
        LambdaQueryWrapper<Organization> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(Organization::getFatherId,0);

        List<Organization> organizations = organizationMapper.selectList(queryWrapper);
        return organizations;
    }

    @Override
    public List<Organization> getOrganizationTwoByOne(Integer fatherId) {
        LambdaQueryWrapper<Organization> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Organization::getFatherId,fatherId);
        queryWrapper.orderByAsc(Organization::getSort);
        List<Organization> organizations = organizationMapper.selectList(queryWrapper);
        organizations.stream().forEach(item->{
            item.setAccountIncome(null);
            item.setAccountMoney(null);
            item.setCommission(null);
            item.setSalesCommission(null);
        });
        return organizations;
    }

    @Override
    public Organization getOrganizationTwoInfo(Integer id) {
        Organization organization = organizationMapper.selectById(id);
        organization.setAccountIncome(null);
        organization.setAccountMoney(null);
        organization.setCommission(null);
        organization.setSalesCommission(null);
        return organization;
    }

}




